package cll;
import static cll.Parameters.*;
// l'antigene est un point de Z⁴,
//une mutation ets un deplacement de 1 pas dans une direction aleatoire
public class Antigen {

	int x;
	int y;
	int z;
	int t;
	
	
	private Antigen(int x, int y, int z, int t){
		this.x=x;
		this.y=y;
		this.z=z;
		this.t=t;
		
		
				
	}
	public static Antigen getTargetAntigen() {
		return  new Antigen(0,0,0,0);
	}

	public String toString(){
		return x+","+y+","+z+","+t;
	}
	
	public Antigen mutated() {
		// TODO Auto-generated method stub
		if (Math.random() < proba_hypermutation){
			int random = (int)(Math.random()*8);
			switch (random){
			case 0  :return new Antigen(x+1,y,z,t);
			case 1  :return new Antigen(x-1,y,z,t);
			case 2  :return new Antigen(x,y+1,z,t);
			case 3  :return new Antigen(x,y-1,z,t);
			case 4  :return new Antigen(x,y,z+1,t);
			case 5  :return new Antigen(x,y,z-1,t);
			case 6  :return new Antigen(x,y,z,t+1);
			case 7  :return new Antigen(x,y,z,t-1);
			
			}
			
			
		}
		return new Antigen(x,y,z,t);
		
	}
	public static Antigen getRandomAntigen() {
		return new Antigen(((int)(Math.random()-0.5)*10),
				((int)(Math.random()-0.5)*10),
				((int)(Math.random()-0.5)*10),
				((int)(Math.random()-0.5)*10));
		
	}
	
	public static int distanceAbsolue(Antigen antigen2, Antigen antigen3){
		return Math.abs(antigen2.x-antigen3.x)+Math.abs(antigen2.y-antigen3.y)+
				Math.abs(antigen2.z-antigen3.z)+Math.abs(antigen2.t-antigen3.t);
	}
	public static double affinity(Antigen antigen2, Antigen antigen3) {
		double distance = 0;
		//System.out.println(antigen2.toString());
		//System.out.println(antigen3.toString());
		distance+=Math.pow((antigen2.x-antigen3.x),2);
		distance+=Math.pow((antigen2.y-antigen3.y),2);
		distance+=Math.pow((antigen2.z-antigen3.z),2);
		distance+=Math.pow((antigen2.t-antigen3.t),2);
		
		return Math.exp(-distance/cst_affinite);
	}
	public Antigen copy() {
		return new Antigen(x, y, z, t);
	}
	
}
